# ！/usr/bin/ python3
# -*- codeing = utf-8 -*-
# @Time :2022/1/1 20:42
# @Author:wuhha
# @File : forms.py
# @Software: PyCharm

from django import forms
from markdownx.fields import MarkdownxFormField

from youpu.models import User, Article, Question


# 定义好字典，给渲染到前端的表单项添加class来增添样式【直接使用crispy更方便】
# bootstrap_form_css_class = {"class": 'form-control'}

# 为了使用celery异步发送邮件进行身份认证，就不用自动生成的表单了
# class RegisterBootstrapForm(forms.ModelForm):
#     """
#     自定义用于注册页面的表单类：
#     1、让password框的type为password
#     2、添加一些Bootstrap样式
#     """
#
#     class Meta:
#         model = User
#         fields = ["username", "password", "email"]
#         widgets = {
#             'username': forms.TextInput(attrs=bootstrap_form_css_class),
#             'password': forms.PasswordInput(attrs=bootstrap_form_css_class),
#             'email': forms.EmailInput(attrs=bootstrap_form_css_class),
#         }

class ArticleForm(forms.ModelForm):
    status = forms.CharField(widget=forms.HiddenInput())  # 隐藏
    edited = forms.BooleanField(widget=forms.HiddenInput(), required=False, initial=False)  # 隐藏
    content = MarkdownxFormField()

    class Meta:
        model = Article
        fields = ["title", "content", "image", "tags", "status", "edited"]

class QuestionForm(forms.ModelForm):
    status = forms.CharField(widget=forms.HiddenInput())  # 隐藏
    content = MarkdownxFormField()

    class Meta:
        model = Question
        fields = ["title", "content", "tags", "status"]